目標是將原本的mongodb搬移到新的server。
本篇文章內容僅包含複製完原本mongodb檔案後,mongod的初始設定的步驟。
包含以下幾個步驟:
將設定檔(mongod.conf)中的replication和security註解。
並更新ip、port、各種檔案路徑(如果需要的話)。
sed -i "/bindIp/c\ bindIp: `hostname -i`, 127.0.0.1" conf/mongod.conf
sed -i '/replication/s/^/#&/' conf/mongod.conf
sed -i '/oplogSizeMB/s/^/#&/' conf/mongod.conf
sed -i '/replSetName/s/^/#&/' conf/mongod.conf
sed -i '/security/s/^/#&/' conf/mongod.conf
sed -i '/authorization/s/^/#&/' conf/mongod.conf
sed -i '/keyFile/s/^/#&/' conf/mongod.conf
mongod.conf
net:
port:
bindIp: `hostname -i`,127.0.0.1
#replication:
# oplogSizeMB:
# replSetName:
#security:
# authorization: enabled
# keyFile:
啟動mongod
mongod --config your_config_path
連線到mongo shell,刪除local的內容。
use local
db.dropDatabase()
use admin
db.shutdownServer()
將設定檔中,前面註解掉的replication和security都拿掉。
sed -i '/replication/s/^#//' conf/mongod.conf
sed -i '/oplogSizeMB/s/^#//' conf/mongod.conf
sed -i '/replSetName/s/^#//' conf/mongod.conf
sed -i '/security/s/^#//' conf/mongod.conf
sed -i '/authorization/s/^#//' conf/mongod.conf
sed -i '/keyFile/s/^#//' conf/mongod.conf
mongod.conf
replication:
oplogSizeMB:
replSetName:
security:
authorization: enabled
keyFile:
啟動mongod
mongod --config your_config_path
rs.initiate()
rs.status()
exit
rs.add( { host: "## HOSTNAME ##:## PORT ##" } )
rs.status()
exit
https://docs.mongodb.com/manual/tutorial/restore-replica-set-from-backup/